package com.liuzhongni.wahahanews.cachetest;

import android.graphics.Bitmap;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

/**
 * Created by dllo on 16/1/18.
 */
public class MyMemoryCache implements ImageLoader.ImageCache {
    private LruCache<String,Bitmap> cache = new LruCache<String,Bitmap>((int) (Runtime.getRuntime().maxMemory()/4)){
        @Override
        protected int sizeOf(String url, Bitmap bitmap) {
            return bitmap.getRowBytes()*bitmap.getHeight();
        }
    };
    @Override
    public Bitmap getBitmap(String url) {
        return cache.get(url);
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
        cache.put(url,bitmap);
    }
}
